﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace Fengsoft.AIBlog.Web.Models
{
    public abstract class ViewModelBase:IValidatableObject
    {
        public bool IsValid
        {
            get
            {
                return !ValidationMessages.Any();
            }
            set
            {
            }
        }
        public List<ValidationMessage> ValidationMessages
        {
            get;
            set;
        }
        public ViewModelBase()
        {
            ValidationMessages=new List<ValidationMessage>();
        }
        public void AddValidationMessage(string message)
        {
            AddValidationMessage(string.Empty,message);
        }
        public void AddValidationMessage(string name,string message)
        {
            ValidationMessages.Add(new ValidationMessage(name,message));
        }
        public void AddValidationMessages(IEnumerable<string> messages)
        {
            foreach (string message in messages)
            {
                AddValidationMessage(message);
            }
        }
        public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            return new List<ValidationResult>(0);
        }
    }
}